// require配置
require.config({
    baseUrl: './src',
    paths: {
        map: "app/initMap",

        labelinfo: "app/labelinfo",
        
        // 政区下钻与上溯相关
        ZQShuttle: "app/zqShuttle/ZQShuttle",
        getZQShuttledata: "app/zqShuttle/getzqdata",

        // olechart相关
        olechart: "app/olechart/olechart",
        pie: "app/olechart/pie",
        bar: "app/olechart/bar",
        line: "app/olechart/line",
        timeLinestatistics: "app/olechart/timeLinestatistics",
        getolechartzqdata: "app/olechart/getzqdata",

        // 政区聚合相关
        ZqPolymerization: "app/zqpolymerization/ZqPolymerization",
        animate: "app/zqpolymerization/animate",
        getzqpolymerizationzqData: "app/zqpolymerization/getzqData",
        threadsQueue: "app/zqpolymerization/threadsQueue",
    },
    waitSeconds: 0
});

require([
    "map","ZQShuttle", "labelinfo", "olechart", "ZqPolymerization"
],function (
    map, ZQShuttle, labelinfo, olechart, ZqPolymerization
) {
    ZQShuttle.init({
        code:"13", 
        minLevel: 1, 
        maxLevel: 3, 
        serverUrl: "http://cj.stgz.org.cn/geoLocation",
        styleCollection: {
            borderStyle: new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: '#000',
                    width: 2
                })
            }),
            highlightStyle: new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: '#000',
                    width: 1,
                    lineDash: [10]
                }),
                fill: new ol.style.Fill({
                    color: 'rgba(11, 95, 255, 0.8)'
                })
            }),
            generalStyle: new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: '#000',
                    width: 1,
                    lineDash: [10]
                }),
                fill: new ol.style.Fill({
                    color: 'rgba(230, 230, 230, 0.8)'
                })
            })
        },
        popFun: function (fea) {
            return '<div>code：' + fea.get("code") +'</div>' + '<div>name：' + fea.get("name") +'</div>';
        }
    });

    olechart.init();

    ZqPolymerization.init({
        serverUrl: "http://cj.stgz.org.cn/geoLocation",
        showField : "num",
        dataField : "num",
        animateSpeed : 1500,
        popOvelayShowFields : ["name"],
        scatteringRadius : 30,
        PopIconUrl : "../../src/source/images/marker.png",
        zoomMapping : {0: [0, 7], 1: [7, 9] , 2: [9, 12], 3: [12, 13], 4: [13, 18]},
        popHtml : function name(fea) {
            let popSpanhtml = '';
            let divWidth = 0;
            let text = fea.get("name");
            if (text) {
                let spanText = "name：" + text;
                popSpanhtml += "<span>" + spanText + "</span>";
                divWidth = spanText.length * 14;
            }
            return {
                html: "<div>" + popSpanhtml + "</div>",
                width: divWidth,
                // height: 200
            };
        },
        rgbcall : function (value, maxValue, minValue) {
            let rate = value / maxValue;
            return {
                stroke: `255, ${255 - parseInt(rate * 255)}, 0`,
                fill: `255, ${255 - parseInt(rate * 255)}, 0`
            }
        },
    });

    labelinfo.init({
        proj: "EPSG:4326",
        serverUrl: 'http://www.stgz.org.cn/mzxzqmvt/xzq/{z}/{x}/{y}/tile.mvt',
        idProp: 'pk_uid',
        showField: ["sheng_name","shi_name","xian_name","xiang_name","cun_name","layer"],
        popHtml: function (fea) {
            let properties = fea.getProperties();
            let htmlDom = "";
            ["sheng_name","shi_name","xian_name","xiang_name","cun_name","layer"].forEach(field => {
                properties[field] && (htmlDom += "<div>" + field + "：" + properties[field] + "</div>");  
            })
            return htmlDom;
        },
        beforeShowLayer: function () {
            map.hideLayer("tiandituLayerbz");
        },
        beforeHideLayer: function () {
            map.showLayer("tiandituLayerbz");
        },
    })


    $("#map_tool .button").on("click", function (e) {
        $(this).siblings().removeClass("selected");
        if ($(this).hasClass("echarts")) {
            ZqPolymerization.setVisible(false);
            labelinfo.setVisible(false);
            ZQShuttle.setVisible(false);
            if ($(this).hasClass("selected")) {
                $(this).removeClass("selected");
                olechart.setVisible(false);
            }else{
                $(this).addClass("selected");
                olechart.setVisible(this.id);
                olechart.setmodel(this.id);
            }
        }
        if(this.id === "ZQ"){
            labelinfo.setVisible(false);
            olechart.setVisible(false);
            ZqPolymerization.setVisible(false);
            if ($(this).hasClass("selected")) {
                $(this).removeClass("selected");
                ZQShuttle.setVisible(false);
            }else{
                $(this).addClass("selected");
                ZQShuttle.setVisible(true);
            }
        }
        if (this.id === "ZqPolymerization") {
            olechart.setVisible(false);
            labelinfo.setVisible(false);
            ZQShuttle.setVisible(false);
            if ($(this).hasClass("selected")) {
                $(this).removeClass("selected");
                ZqPolymerization.setVisible(false);
            }else{
                $(this).addClass("selected");
                ZqPolymerization.setVisible(true);
            }
        }
        if (this.id === "ZQ_lable") {
            olechart.setVisible(false);
            ZQShuttle.setVisible(false);
            ZqPolymerization.setVisible(false);
            if ($(this).hasClass("selected")) {
                $(this).removeClass("selected");
                labelinfo.setVisible(false);
            }else{
                $(this).addClass("selected");
                labelinfo.setVisible(true);
            }
        }
    })

    window.ZQShuttle = ZQShuttle;
    window.labelinfo = labelinfo;
    window.olechart = olechart;
})